$(function () {
    //切换提现账号
    $(document).on('click','.change-uAccount-btn', function () {
        $.ajax({
            url: baseloaction + '/mobile/uc/cash/findUserCashAccountList',
            type:'post',
            dataType:'json',
            success:function (result) {
                if(result.success==true){
                    var uAccountButtons = [
                        {
                            text: '请选择提现账号',
                            label: true
                        }
                    ];
                    var list = result.entity;
                    $.each(list,function (index,em) {
                        var obj = {};
                        if(em.accountType ==1){//支付宝
                            obj.text = '<div class="change-uAccount-actions-item"><em class="iconfont icon-zhifubao c-blue vam" style="font-size: 1.1rem;"></em><span class="vam ml5">支付宝</span><small class="fs7 vam">（'+em.account+'）</small></div>';
                        }else{//微信
                            obj.text = '<div class="change-uAccount-actions-item"><em class="iconfont icon-winxin c-green vam" style="font-size: 1.2rem;"></em><span class="vam ml5">微信ID</span><small class="fs7 vam">（'+em.account+'）</small></div>';
                        }
                        obj.onClick = function(){
                            $("#account").val(em.account);
                            $("#realName").val(em.realName);
                            $("#accountType").val(em.accountType);
                            //'icon-zhifubao c-blue':'icon-winxin c-green'
                            if(em.accountType==1){//支付宝
                                $(".change-uAccount-btn .iconfont").removeClass('icon-winxin').removeClass('c-green').addClass('icon-zhifubao c-blue');
                                $("#zf-show-name").text('支付宝');
                            }else{//微信
                                $("#zf-show-name").text('微信');
                                $(".change-uAccount-btn .iconfont").removeClass('icon-zhifubao').removeClass('c-blue').addClass('icon-winxin c-green');
                            }
                            $("#zf-show-text").text(em.realName+'|'+em.account);
                        }
                        uAccountButtons.push(obj);
                    });
                    var uAccountButtons2 = [
                        {
                            text: '取消',
                            bg: 'danger'
                        }
                    ];
                    var uAccountGroups = [uAccountButtons, uAccountButtons2];
                    $.actions(uAccountGroups);
                }else{
                    $.alert(result.message);
                }
            },
            error:function (error) {
                $.alert('系统错误，获取账号数据失败');
            }
        });
    }).on('click','#all-cash-m',function () {
        var _this = $(this);
        var cashM = _this.data('cash');
        $("#price").val(cashM);
    }).on('keyup','#price',function () {
        var reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/;
        var _this = $(this);
        var price = _this.val();
        if(!reg.test(price)){
            _this.val('');
        }
        var cash = $("#all-cash-m").data('cash');
        if(price > cash){
            _this.val(cash);
        }
    });

    //提现申请 反馈
    applyWithdrawFn()
})

// 提现申请 反馈
var applyWithdrawFn = function () {

    $(document).on('click', '.applyWithdrawBtn', function () {
        var account = $("#account").val();
        var accountType = $("#accountType").val();
        var price = $("#price").val();
        if(price==null || $.trim(price)==''){
            $.alert("最小提现金额为1到1000");
            return;
        }
        $.ajax({
            url:baseloaction +'/mobile/uc/cash/saveCashRecord',
            type:'post',
            dataType:'json',
            data:{
                'account':account,
                'accountType':accountType,
                'price':price
            },
            success:function (result) {
                if(result.success==true){
                    var _ele = $('#applyWithdraw-ele').val();
                    $.alert(_ele,function () {
                        window.location.href = baseloaction + '/mobile/uc/cash/findUserCashRecordList';
                    })
                }else{
                    $.alert(result.message);
                }
            },
            error:function (error) {
                $.alert('系统错误，申请提现失败');
            }
        });
        $('.modal-in').find('.modal-button-bold').text('知道了').attr('style', '');
    });
}